package us.wili.dev.third.util.example.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import us.wili.dev.common.util.sms.aliyun.AliyunSmsProperties;
import us.wili.dev.common.util.sms.aliyun.AliyunSmsUtil;

/**
 * author: lefore
 * date: 2018/10/15
 */
@Configuration
@EnableConfigurationProperties(SmsConfig.SmsPropertiesCreator.class)
public class SmsConfig {

    @Bean
    public AliyunSmsUtil aliyunSmsUtil(SmsPropertiesCreator propCreator) {
        AliyunSmsProperties prop = propCreator.getSms();
        return new AliyunSmsUtil(prop);
    }

    @ConfigurationProperties
    public static class SmsPropertiesCreator {

        private AliyunSmsProperties sms;

        public AliyunSmsProperties getSms() {
            return sms;
        }

        public void setSms(AliyunSmsProperties sms) {
            this.sms = sms;
        }
    }
}
